from random import *
import tkinter as tk
from tkinter import *
from tkinter import ttk
def click():
    global k
    global pp
    p = ht.get()
    if p.isdigit():
        if int(p) < cv:
            al.config(text = "Загаданное число больше")
            
        elif int(p) == cv:
            al.config(text = "Вы угадали")
            
        else:
            al.config(text = "Загаданное число меньше")
        k += 1
        al2.config(text = pp + str(k))
        
    return 0

def fin():
    window.destroy()
    return 0


cv = randint(1, 200)
pp = "Попыток: "
k = 0
window = Tk()
window.title("Угадай число")
window.geometry('400x300')

frame = Frame(window, padx = 10, pady = 10)
frame.pack(expand = True)
hl = Label(frame, text = "Введите число от 1 до 200\nи нажмите кнопку 'Press'")
hl.grid(row = 2, column = 2)
ht = Entry(frame)
ht.grid(row = 3, column = 2)

btn = ttk.Button(frame, text = "Press", command = click)
btn.grid(row = 4, column = 2)
al = ttk.Label(frame, text = " ")
al.grid(row = 5, column = 2)

al2 = ttk.Label(frame, text = pp + str(k))
al2.grid(row = 6, column = 2)

btn2 = ttk.Button(frame, text = "Закрыть окно", command = fin)
btn2.grid(row = 8, column = 2)

window.mainloop()
